//
//  BasePanel.m
//  AsyncImages
//
//  Created by Matthew on 11-12-27.
//  Copyright 2011年 develop4u.gr. All rights reserved.
//

#import "BaseInfoPanel.h"
#import "ColorUtil.h"

#define INFO_TABLE_WIDTH 320
#define INFO_TABLE_HEIGHT 365

@implementation BaseInfoPanel

@synthesize suffix;
@synthesize inited;
@synthesize topBarType;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // Initialization code
        self.backgroundColor = [ColorUtil stringHexToUIColor:@"0xf0f0f0"];
        
        useFeaturedImg = TRUE;
        useLogo = TRUE;
        useExitBtn = FALSE;
        inited = FALSE;
        topBarType  = 0;
        
        infoTopBar = [[TopBar alloc] initWithFrame:CGRectMake(0, 0, INFO_TABLE_WIDTH,65)];
        [self addSubview:infoTopBar];
        
        infoTable = [[XMLTable alloc] initWithFrame:CGRectMake(0,infoTopBar.frame.size.height, INFO_TABLE_WIDTH, INFO_TABLE_HEIGHT)];
        [self addSubview:infoTable];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

-(void) trigger:(NSString *) tableInfoWebLink
   infoBarTitle:(NSString *) inInfoBarTitle
            suffix:(NSString *) inSuffix
{
    if (!inited) 
    {
        infoTopBar.suffix = inSuffix;
        infoTopBar.useReturnBtn = useExitBtn;
        [infoTopBar initUI:inInfoBarTitle logoDisplay:useLogo type:topBarType];

        if (innerSuffix != Nil) 
        {
            infoTable.suffix = innerSuffix;
        }
        else
        {
            infoTable.suffix = inSuffix;
        }
        [infoTable configMsg];
        [infoTable triggerByURL:tableInfoWebLink useFeatureImg:useFeaturedImg];
    }
    else
    {
        infoTable.xmlPath = tableInfoWebLink;
        [infoTable refresh]; 
        
        [infoTopBar updateTitle:inInfoBarTitle];
    }

    
    inited = TRUE;
}

-(void) setUpLogoAndImg:(BOOL) inUseLogo
            featuredImg:(BOOL) inUseFeaturedImg
{
    useFeaturedImg = inUseFeaturedImg;
    useLogo = inUseLogo;
}

-(void) setUpReturnBtn:(BOOL) inReturnBtnStatus
{
    useExitBtn = inReturnBtnStatus;
}

-(void) setInnerSuffix:(NSString *) inInnerSuffix
{
    innerSuffix = [[NSString alloc] initWithString:inInnerSuffix];
}

-(void) releaseSelectedNode
{
    [infoTable releaseSelectedNode];
}

-(void) refresh
{
    [infoTable refresh];
}

-(NSString *) getIdentify
{
    return infoTable.identifier;
}

-(void) setAtomData:(NSString *) feedAndUnit
               atom:(NSString *) inAtomUnit
               feed:(NSString  *) feedUnit
{
    if (infoTable) 
    {
        [infoTable setAtomData:feedAndUnit
                                      atom:inAtomUnit 
                                       feed:feedUnit];
    }
}

-(void) configTable:(int) inTableWidth
        tableHeight:(int) inTableHeight
         tableWidth:(int) inTableRowHeight
     tableUnitStyle:(int) inTableUnitStyle
{
    if (infoTable) 
    {
        [infoTable configTable:inTableWidth
                   tableHeight:inTableHeight
                    tableWidth:inTableRowHeight
                tableUnitStyle:inTableUnitStyle];
    }
}

-(void) setUpUseCharacterPanel
{
    if (infoTable) 
    {
        infoTable.useCharacterPanel = TRUE;
    }
}

- (void)dealloc
{
    [super dealloc];
}

@end
